package markgame2dphys;

import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;

public final class MarkGameUtils {

	private MarkGameUtils() {}
	
	public static float dist(float x1, float y1, float x2, float y2){
		float dx = x2-x1;
		float dy = y2-y1;
		return (float)Math.sqrt(dx*dx + dy*dy);
	}
	
	public static Vector2f convertLocalToGlobal(Body body, Vector2f local){
		Vector2f pos = (Vector2f)body.getPosition();
		float rot = body.getRotation();
		
		//carteziano -> polar
		float angle = (float)Math.atan2(-local.y, local.x) - rot;
		float dist = dist(0,0,local.x,local.y);
		
		//polar -> carteziano
		float anchor1x = pos.x + (float)Math.cos(angle)*dist;
		float anchor1y = pos.y - (float)Math.sin(angle)*dist;
		
		return new Vector2f(anchor1x, anchor1y);
	}
	
}
